package cn.sdut.socket.ip;

import java.net.InetAddress;

/**
 * Created by majiatao
 *
 * Java中涉及的类：InetAddress
 *      - byte[] getAddress()  返回原始地址
 *      - getLocalHost() 返回本地主机
 *      - InetAddress getByName(String host) 给定主机名的情况下确认主机的ip地址
 */
public class IPDemo {
    public static void main(String[] args) throws Exception{
        // 获取本地主机
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println("LocalHost：" + localHost);
        System.out.println("LocalHost-Ip:" + localHost.getHostAddress());
        System.out.println("LocalHost-Name:" + localHost.getHostName());
        // 获取其他主机
        InetAddress byName = InetAddress.getByName("www.baidu.com");
         System.out.println(byName.getHostAddress()); // 180.101.49.12
        System.out.println(byName.getHostName()); // www.baidu.com

    }
}
